<?php

abstract class fvModule {
    protected $template_dir;
    protected $compile_dir;
    protected $current_page;
    protected $className;

    public static $FV_NO_MODULE = "";

    function __construct($template, $compile, $current_page) {
        $this->template_dir = $template;
        $this->compile_dir = $compile;
        $this->current_page = $current_page;
    }

    function __set($name, $value) {
    	$this->__assign($name, $value);
    }

    protected function getPage() {
        return $this->current_page;
    }

    protected function __display($template_name) {
        $old_template_dir = fvSite::$Template->template_dir;
        $old_compile_dir = fvSite::$Template->compile_dir;
        fvSite::$Template->template_dir = $this->template_dir;
        fvSite::$Template->compile_dir = $this->compile_dir;
        $result = fvSite::$Template->fetch($template_name);

        fvSite::$Template->template_dir = $old_template_dir;
        fvSite::$Template->compile_dir = $old_compile_dir;
        return $result;
    }


    protected function __assign($key, $value = null) {
        if (is_null($value)) {
            fvSite::$Template->assign($key);
        }
        else {
            fvSite::$Template->assign($key, $value);
        }
    }

    function showModule($module, $params = array(), $id = null) {
        if (strlen((string)$module) == 0) $module = "index";
        $this->getParams()->setParameter("moduleID", $id);
        $moduleName = "show" . ucfirst(strtolower($module));
        if (is_callable(array($this, $moduleName))) {
            return call_user_func(array($this, $moduleName), $params);
        }
        else return fvModule::$FV_NO_MODULE;
    }

    function getRequest() {
        return fvSite::$fvRequest;
    }

    function getParams() {
    	return fvSite::$fvParams;
    }
}

?>
